package com.demo.las.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

@Entity
@Table(name = "affair_catalog", indexes = {
    @Index(name = "idx_affair_catalog_code", columnList = "code", unique = true),
    @Index(name = "idx_affair_catalog_category", columnList = "category_code")
})
public class AffairCatalog {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "大类编码不能为空")
    @Column(name = "category_code", nullable = false)
    private Integer categoryCode;

    @NotNull(message = "事务项编码不能为空")
    @Column(name = "item_code", nullable = false)
    private Integer itemCode;

    @NotBlank(message = "大类名称不能为空")
    @Size(max = 100)
    @Column(name = "category_name", nullable = false)
    private String categoryName;

    @NotBlank(message = "事务名称不能为空")
    @Size(max = 200)
    @Column(name = "item_name", nullable = false)
    private String itemName;

    @NotBlank(message = "事务编号不能为空")
    @Size(max = 50)
    @Column(name = "code", nullable = false, unique = true)
    private String code; // 例如 "1-1"

    @CreationTimestamp
    @Column(name = "create_time", updatable = false)
    private LocalDateTime createTime;

    @UpdateTimestamp
    @Column(name = "update_time")
    private LocalDateTime updateTime;

    @Column(name = "active", nullable = false)
    private Boolean active = true;

    // Getter & Setter
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public Integer getCategoryCode() { return categoryCode; }
    public void setCategoryCode(Integer categoryCode) { this.categoryCode = categoryCode; }

    public Integer getItemCode() { return itemCode; }
    public void setItemCode(Integer itemCode) { this.itemCode = itemCode; }

    public String getCategoryName() { return categoryName; }
    public void setCategoryName(String categoryName) { this.categoryName = categoryName; }

    public String getItemName() { return itemName; }
    public void setItemName(String itemName) { this.itemName = itemName; }

    public String getCode() { return code; }
    public void setCode(String code) { this.code = code; }

    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }

    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }

    public Boolean getActive() { return active; }
    public void setActive(Boolean active) { this.active = active; }
}